<style>
    .link{color:black;}
    .link:hover{text-decoration: none;}
</style>

<?php if($total_geral = count($this->eventos)){ ?>
<div>
    
<form id="frmSearch" class="form-search pull-right">
  <input id="search" name="search" type="text" class="input-xlarge search-query" />
</form>
    
<table id="tb_eventos" class="table table-condensed table-striped">
    <tr>
        <th><a style="cursor: pointer;" onclick="classificar('evento');">Evento</a></th>
        <th style="text-align: center;">PAC</th>
        <th style="text-align: center;">Início</th>
        <th style="text-align: center;">Término</th>
        <th style="text-align: center;">Duração</th>
        <th style="text-align: center;">Carga Hor.</th>
        <th style="width:60px;">&nbsp;</th>
    </tr>
    <?php foreach($this->eventos as $eventos): ?>
    <tr>
        <td>
            <a class="link" href="default/evento/detalhe/id/<?php echo $eventos->id; ?>">
            <?php echo $eventos->evento ;?></a>
        </td>
        <td style="text-align: center; padding: 2px 0 0 0;"><?php if($eventos->pac): ?>
            <img alt="PAC"  title="PAC" src="<?php echo $this->baseUrl().'/images/tick.png'; ?>"></a>
        <?php endif;?></td>
        <td style="text-align: center; "><?php echo $this->FormataData($eventos->dt_inicio);?></td>
        <td style="text-align: center; "><?php echo $this->FormataData($eventos->dt_termino);?></td>
        <td style="text-align: center; "><?php 
        $dt_inicio  = new Zend_Date($eventos->dt_inicio,'pt_BR');
        $dt_termino = new Zend_Date($eventos->dt_termino,'pt_BR');
        if($dt_inicio->toString('yyyy-MM-dd')!='1999-11-30' && $dt_termino->toString('yyyy-MM-dd')!='1999-11-30'):
            $diff = $dt_termino->sub($dt_inicio)->toValue();
            echo $this->plural(floor($diff/(3600*24)+1),'dia','dias');
        endif;?>
        <td style="text-align: center; "><?php echo $eventos->carga_horaria;?></td>

        
        <td style="padding:0px 2px;">
            <a href="default/evento/form/id/<?php echo $eventos->id;?>">
            <img alt="Editar"  title="Editar" src="<?php echo $this->baseUrl().'/images/edit.png'; ?>"></a>
            
            <a href="default/evento/delete/id/<?php echo $eventos->id;?>">
            <img alt="Apagar" title="Apagar" src="<?php echo $this->baseUrl().'/images/trash.png'; ?>"></a>
        </td>
    </tr>
    <?php endforeach; ?>
</table>
<?php echo $this->plural($total_geral,'Apenas %s evento encontrado!','Foram encontrados %s eventos.'); ?>
</div>
<?php } else {echo "<br/><br/>Nenhum evento encontrado!";} ?>

<script>
	$('#frmSearch').submit(function(){
        $('#loading').show();
        $.post('default/evento/ajax-filtrar', $(this).serialize(), function(data){
            $('#div_index').html(data);
            $('#loading').hide();
        });
        return false;
	});

    jQuery(function(){
        $('#search').focus();
    })
</script>
